<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	
	<xsl:include href="../main.xsl" />
	<xsl:include href="controls.xsl" />
	<xsl:include href="menu.xsl" />
	<xsl:include href="../common/navigation.xsl" />
	<xsl:include href="blocks.xsl" />
	<xsl:include href="blogsBars.xsl" />
	<xsl:include href="../users/ownerBar.xsl" />
	<xsl:include href="rss.xsl" />
	
	<xsl:template match="/data">
		<html>
		
		<head>
			<title>
				<xsl:value-of select="$pageTitle" />
			</title>
			<xsl:call-template name="meta-head" />
			<xsl:call-template name="rss">
				<xsl:with-param name="userLogin">
					<xsl:value-of select="response/@user-login" />
				</xsl:with-param>
			</xsl:call-template>
			<link rel="stylesheet" href="{$baseURI}/css/blogs/blogs.css" type="text/css" media="all" />
			<link rel="stylesheet" href="{$baseURI}/css/owner-bar.css" type="text/css" media="all" />
			<script type="text/javascript" src="{$baseURI}/js/blogs.js" />
		</head>
		<body>
			
			<xsl:call-template name="top-userbar" />

			<div class="page-header">
				<xsl:call-template name="logo" />

				<xsl:call-template name="menu" />
			</div>

			<div class="page-content-wrapper">
				<div class="page-blocks">
					<xsl:call-template name="default-blocks-top" />
					
					<div class="block">
						<div class="header">Прямой эфир</div>
						<div class="content">
							<xsl:apply-templates select="document('xmodule://comments/getLive/10')/data/response" mode="block-live-comments" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
					
					<div class="block">
						<div class="header">Облако тегов</div>
						<div class="content tags">
							<xsl:apply-templates select="document('xmodule://blogs/getTagsCloud')/data/response" mode="block-tags-cloud" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
					
					<div class="block">
						<div class="header">Популярные блоги</div>
						<div class="content">
							<xsl:apply-templates select="document('xmodule://blogs/getBlogsBlock')/data/response" mode="block-blogs" />
						</div>
						
						<i class="corner-f8-10 tl"></i>
						<i class="corner-f8-10 tr"></i>
						<i class="corner-f8-10 br"></i>
						<i class="corner-f8-10 bl"></i>
					</div>
				</div>
	
				<div class="page-content">
					<xsl:apply-templates select="response" />
				</div>
			</div>

			<xsl:call-template name="footer" />
		</body>
		</html>
	</xsl:template>
	
	
	
	<!-- RESPONSE -->
	<xsl:template match="response">	
		
		<xsl:choose>
			<xsl:when test="$method = 'tag'">
				<div class="tag-search">
					<form action="{$baseURI}/blogs/tag/go" method="post">
						<input id="tag_name" class="tag" type="text" name="tag">
							<xsl:attribute name="value">
								<xsl:value-of select="@tag-filter" />
							</xsl:attribute>
						</input>
						<xsl:text> </xsl:text>
						<input type="submit" value="→" />
					</form>
				</div>
				<script type="text/javascript">
					$('#tag_name')
						.blur (function () {
							if ($(this).val() == '') {
								$(this)
									.val('Введите тег')
									.css('color', '#dfdfdf');
							}
						})
						.click (function () {
							if ($(this).val() == 'Введите тег') {
								$(this)
									.val('')
									.css ('color', '#000');
							}
						});
					
					
					if ($('#tag_name').val() == '') {
						$('#tag_name')
							.val('Введите тег')
							.css('color', '#dfdfdf');
					}
				</script>
			</xsl:when>
			
			<xsl:when test="$method = 'user'">
				<xsl:apply-templates select="document(concat('xmodule://users/getUser/', @user-id))/data/response/object[@type='user']" mode="ownerbar" />
			</xsl:when>
			
			<xsl:when test="@blog-id != '0'">
				<xsl:apply-templates select="document(concat('xmodule://blogs/getBlog/', @blog-id))/data/response/object" mode="blog-bar" />
			</xsl:when>
			
			<xsl:otherwise>
				<div class="tabs">
					<ul>
						<li>
							<xsl:if test="$method='__default'">
								<xsl:attribute name="class">selected</xsl:attribute>
							</xsl:if>
							<a href="{$baseURI}/blogs">Популярные</a>
							
							<i class="corner-mask-eee-5 tl"></i>
							<i class="corner-mask-eee-5 tr"></i>
							<i class="corner-mask-eee-5 br"></i>
							<i class="corner-mask-eee-5 bl"></i>
						</li>
						<li>
							<xsl:if test="$method='all'">
								<xsl:attribute name="class">selected</xsl:attribute>
							</xsl:if>
							<a href="{$baseURI}/blogs/all">Все</a>
							
							<i class="corner-mask-eee-5 tl"></i>
							<i class="corner-mask-eee-5 tr"></i>
							<i class="corner-mask-eee-5 br"></i>
							<i class="corner-mask-eee-5 bl"></i>
						</li>
						<li>
							<xsl:if test="$method='thematic'">
								<xsl:attribute name="class">selected</xsl:attribute>
							</xsl:if>
							<a href="{$baseURI}/blogs/thematic">Тематические</a>
							
							<i class="corner-mask-eee-5 tl"></i>
							<i class="corner-mask-eee-5 tr"></i>
							<i class="corner-mask-eee-5 br"></i>
							<i class="corner-mask-eee-5 bl"></i>
						</li>
						<li>
							<xsl:if test="$method='personal'">
								<xsl:attribute name="class">selected</xsl:attribute>
							</xsl:if>
							<a href="{$baseURI}/blogs/personal">Персональные</a>
							
							<i class="corner-mask-eee-5 tl"></i>
							<i class="corner-mask-eee-5 tr"></i>
							<i class="corner-mask-eee-5 br"></i>
							<i class="corner-mask-eee-5 bl"></i>
						</li>
					</ul>
				</div>
			</xsl:otherwise>
		</xsl:choose>
		
		<xsl:if test="count (object) = 0">
			<div class="simple-message">Здесь нет записей</div>
		</xsl:if>
		
		<xsl:apply-templates select="object" />
		
		<xsl:apply-templates select="pages" mode="pages-navigation">
			<xsl:with-param name="href">
				<xsl:value-of select="$baseURI" />
				<xsl:choose>
					<xsl:when test="$method = 'blog'">
						<xsl:text>/blog/</xsl:text>
						<xsl:value-of select="@blog-name" />
					</xsl:when>
					
					<xsl:otherwise>
						<xsl:text>/blogs</xsl:text>
						<xsl:if test="$method != '__default'">
							<xsl:text>/</xsl:text>
							<xsl:value-of select="$method" />
						</xsl:if>
						<xsl:if test="@user-login != ''">
							<xsl:text>/</xsl:text>
							<xsl:value-of select="@user-login" />
						</xsl:if>
						<xsl:if test="@tag-filter != ''">
							<xsl:text>/</xsl:text>
							<xsl:value-of select="@tag-filter" />
						</xsl:if>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
		</xsl:apply-templates>
	</xsl:template>
	
	<xsl:template match="object[@type='article']">
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="blogAlias" select="property[@name='blog_alias']/value" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<div class="post article">
			<xsl:if test="property[@name='draft']/value = '1'">
				<xsl:attribute name="class">post article draft</xsl:attribute>
			</xsl:if>
			
			<h2>
				<xsl:if test="property[@name='draft']/value = '1'">
					<span class="draft">
						<img src="{$baseURI}/images/post-closed.png" title="Черновик" alt="Черновик" />
					</span>
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value != '0'">
					<a class="blog-name" href="{$baseURI}/blog/{$blogAlias}">
						<xsl:value-of select="property[@name='blog_title']/value" />
					</a>
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value = '0'">
					<a class="blog-name personal" href="{$baseURI}/blogs/user/{$userLogin}">
						<xsl:text>Блог им. </xsl:text>
						<xsl:value-of select="$userLogin" />
					</a>
				</xsl:if>
				<xsl:text> → </xsl:text>
				<a class="title" href="{$baseURI}/post/article/{@id}">
					<xsl:value-of select="property[@name='title']/value" disable-output-escaping="yes" />
				</a>
			</h2>
			
			<div class="content">
				<xsl:value-of select="property[@name='text']/value" disable-output-escaping="yes" />
			</div>
			
			<div class="tags">
				<xsl:for-each select="property[@name='tags']/value">
					<a>
						<xsl:attribute name="href">
							<xsl:value-of select="concat ($baseURI, '/blogs/tag/', .)" />
						</xsl:attribute>
						<xsl:value-of select="." disable-output-escaping="yes" />
					</a>
					<xsl:if test="position() != $countTags">
						<xsl:text>, </xsl:text>
					</xsl:if>
				</xsl:for-each>
			</div>
			
			<xsl:call-template name="article-options" />
		</div>
	</xsl:template>
	
	<xsl:template match="object[@type='link']">
		<xsl:param name="countTags" select="count (property[@name='tags']/value)" />
		<xsl:param name="blogAlias" select="property[@name='blog_alias']/value" />
		<xsl:param name="userLogin" select="property[@name='user_login']/value" />
		
		<div class="post link">
			<xsl:if test="property[@name='draft']/value = '1'">
				<xsl:attribute name="class">post link draft</xsl:attribute>
			</xsl:if>
			
			<h2>
				<xsl:if test="property[@name='draft']/value = '1'">
					<span class="draft">
						<img src="{$baseURI}/images/post-closed.png" title="Черновик" alt="Черновик" />
					</span>
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value != '0'">
					<a class="blog-name" href="{$baseURI}/blog/{$blogAlias}">
						<xsl:value-of select="property[@name='blog_title']/value" />
					</a>
				</xsl:if>
				<xsl:if test="property[@name='blog_id']/value = '0'">
					<a class="blog-name personal" href="{$baseURI}/blogs/user/{$userLogin}">
						<xsl:text>Блог им. </xsl:text>
						<xsl:value-of select="$userLogin" />
					</a>
				</xsl:if>
				<xsl:text> → </xsl:text>
				<a class="title link">
					<xsl:attribute name="href">
						<xsl:value-of select="concat ($baseURI, '/blogs/link/', @id)" />
					</xsl:attribute>
					<xsl:value-of select="property[@name='title']/value" disable-output-escaping="yes" />
				</a>
			</h2>
			
			<div class="content">
				<xsl:value-of select="property[@name='description']/value" disable-output-escaping="yes" />
			</div>
			
			<div class="tags">
				<xsl:for-each select="property[@name='tags']/value">
					<a>
						<xsl:attribute name="href">
							<xsl:value-of select="concat ($baseURI, '/blogs/tag/', .)" />
						</xsl:attribute>
						<xsl:value-of select="." disable-output-escaping="yes" />
					</a>
					<xsl:if test="position() != $countTags">
						<xsl:text>, </xsl:text>
					</xsl:if>
				</xsl:for-each>
			</div>
			
			<xsl:call-template name="article-options" />
			
		</div>
	</xsl:template>
	
</xsl:stylesheet>